package com.iqiu.cms.util;

import java.sql.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class StoredProcedureTools {

    /**
     * 主函数 调用存储过程(测试使用)
     * @param args
     */
    public static void main(String[] args) {

        callStore("2019-01-20");
    }

    public static void callStore(String calcDate){
        // 返回的结果集
        Connection conn = null;
        Statement stmt = null;

        try {
            conn = com.iqiu.cms.util.DBUtil.getConn();
            stmt = conn.createStatement();
            //调用存储过程
            CallableStatement cstmt = conn.prepareCall("{call executeAllProcedure(?)}");
            //在我这里第1个？是输入参数
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            try {
                cstmt.setDate(1,new Date(sdf.parse(calcDate).getTime()));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            //执行
            cstmt.execute();

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
                if(conn != null) {
                    conn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}